package com.c.ctgproject.wiget.common

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import com.c.ctgproject.R
import com.c.ctgproject.utils.Utils
import com.c.ctgproject.utils.pickerimage.utils.ScreenUtil
import kotlinx.android.synthetic.main.activity_service_order_edit.view.*
import org.jetbrains.anko.singleLine
import org.jetbrains.anko.textColor

/**
 *作者:LiBW
 *创建日期: 2021/7/13
 *描述:横向Layout 前方文字固定占比 前后文字可填入 默认有一个marginBottom 1dp
 */
class CarInfoLayout : LinearLayoutCompat {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        val view = LayoutInflater.from(context).inflate(R.layout.view_car_info_layout, this)
        mStartTV = view.findViewById(R.id.mStartTV)
        mEndTV = view.findViewById(R.id.mEndTV)
        val a = context.obtainStyledAttributes(attrs, R.styleable.ServiceDetailLayout)
        val str = a.getString(R.styleable.ServiceDetailLayout_mStartTV)
        if (str != null) setStartTV(str)
        val padding = a.getBoolean(R.styleable.ServiceDetailLayout_mNoPadding, false)
        if (padding) {
            val param = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
            mStartTV?.layoutParams = param
        }
        val endTextSize = a.getDimensionPixelSize(R.styleable.ServiceDetailLayout_mEndTextSize, 0)
        if (endTextSize != 0) {
            mEndTV?.textSize = ScreenUtil.px2dip(endTextSize.toFloat()).toFloat()
        }
        a.recycle()
    }

    constructor(context: Context, left: String, right: String,singleLine:Boolean=true) : super(context) {
        val view = LayoutInflater.from(context).inflate(R.layout.view_car_info_layout, this)
        mStartTV = view.findViewById(R.id.mStartTV)
        mEndTV = view.findViewById(R.id.mEndTV)
       if (!singleLine){
           mEndTV?.singleLine=false
       }

        setStartTV(left)
        textSet(right)
    }

    private var mStartTV: TextView? = null
    private var mEndTV: TextView? = null


    fun setStartTV(str: String) {
        mStartTV?.text = str
    }

    fun textSet(str: String) {
        mEndTV?.text = str
    }
}